package com.inforich.orderManage.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import java.util.Arrays;
import cn.hutool.core.bean.BeanUtil;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestParam;
import com.inforich.common.annotation.Log;
import com.inforich.common.core.controller.BaseController;
import com.inforich.common.core.domain.AjaxResult;
import com.inforich.common.enums.BusinessType;
import com.inforich.orderManage.domain.BookingDriverDrivers;
import com.inforich.orderManage.service.IBookingDriverDriversService;
import com.inforich.common.utils.poi.ExcelUtil;

/**
 * 预约单司机关系表Controller
 *
 * @author hjm
 * @date 2022-10-26
 */
@RestController
@RequestMapping("/orderManage/bookingDriver")
public class BookingDriverDriversController extends BaseController {

  @Autowired
  private IBookingDriverDriversService bookingDriverDriversService;

  /**
   * 查询预约单司机关系表列表
   */
  @PreAuthorize("@ss.hasPermi('orderManage:bookingDriver:list')")
  @GetMapping("/list")
  public Page<BookingDriverDrivers> list(Page<BookingDriverDrivers> page,
      BookingDriverDrivers bookingDriverDrivers) {
    Map<String, Object> map = beanToMap(bookingDriverDrivers);
    bookingDriverDriversService.pageBookingDriverDrivers(page, map);
    return page;
  }


  /**
   * 导出预约单司机关系表列表
   */
  @PreAuthorize("@ss.hasPermi('orderManage:bookingDriver:export')")
  @Log(title = "预约单司机关系表", businessType = BusinessType.EXPORT)
  @PostMapping("/export")
  public void export(HttpServletResponse response, BookingDriverDrivers bookingDriverDrivers) {
    Map<String, Object> map = beanToMap(bookingDriverDrivers);
    List<BookingDriverDrivers> list = bookingDriverDriversService.listBookingDriverDrivers(map);
    ExcelUtil<BookingDriverDrivers> util = new ExcelUtil<BookingDriverDrivers>(
        BookingDriverDrivers.class);
    util.exportExcel(response, list, "预约单司机关系表数据");
  }

  /**
   * 获取预约单司机关系表详细信息
   */
  @PreAuthorize("@ss.hasPermi('orderManage:bookingDriver:query')")
  @GetMapping(value = "/{bookingId}")
  public AjaxResult getInfo(@PathVariable("bookingId") String bookingId) {
    return AjaxResult.success(bookingDriverDriversService.getById(bookingId));
  }

  /**
   * 新增预约单司机关系表
   */
  @PreAuthorize("@ss.hasPermi('orderManage:bookingDriver:add')")
  @Log(title = "预约单司机关系表", businessType = BusinessType.INSERT)
  @PostMapping
  public AjaxResult add(@Validated @RequestBody BookingDriverDrivers bookingDriverDrivers) {
    return toAjax(bookingDriverDriversService.save(bookingDriverDrivers));
  }

  /**
   * 修改预约单司机关系表
   */
  @PreAuthorize("@ss.hasPermi('orderManage:bookingDriver:edit')")
  @Log(title = "预约单司机关系表", businessType = BusinessType.UPDATE)
  @PutMapping
  public AjaxResult edit(@Validated @RequestBody BookingDriverDrivers bookingDriverDrivers) {
    return toAjax(bookingDriverDriversService.updateById(bookingDriverDrivers));
  }

  /**
   * 删除预约单司机关系表
   */
  @PreAuthorize("@ss.hasPermi('orderManage:bookingDriver:remove')")
  @Log(title = "预约单司机关系表", businessType = BusinessType.DELETE)
  @DeleteMapping("/{bookingIds}")
  public AjaxResult remove(@PathVariable String[] bookingIds) {
    return toAjax(bookingDriverDriversService.removeByIds(Arrays.asList(bookingIds)));
  }
}
